﻿using GDI_应用案例.Pages.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GDI_应用案例.Pages
{
    [FormPage(4, "移动验证码(制作中)")]
    public partial class PageMobileVerificationCode : PageBase
    {
        private readonly MobileVerificationCode verificationCode;
        public PageMobileVerificationCode()
        {
            InitializeComponent();
            verificationCode = new MobileVerificationCode();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var result = verificationCode.Create();
            pictureBox1.Image?.Dispose();
            pictureBox1.Image = result.Bitmap;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.Filter = "所有文件(*.*)|*.*";
                openFileDialog.Multiselect = false;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string filePath = openFileDialog.FileName;
                    verificationCode.SetImage(filePath);
                    pictureBox2.Image?.Dispose();
                    pictureBox2.Image=new Bitmap(filePath);
                }
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            if (pictureBox1.Image == null) return;
            FrmShowImage frmShow = new FrmShowImage(pictureBox1.Image);
            frmShow.ShowDialog();
            frmShow.Dispose();
        }
    }
}
